﻿using System;
using DomainModel.Domain.Bases;
using DomainModel.Utils;

namespace DomainModel.Domain.Model.ServiceModel
{
    public class ServiceRole : Entity<ServiceRole, ServiceRoleId>, IEquatable<ServiceRole>
    {
        public ServiceRole(ServiceRoleId id)
            : base(id)
        {
            Validate.NotNull(id, "ServiceRoleId must not be null");   
            CreateModifyInfo = new CreateModifyInfo();
        }

        public virtual CreateModifyInfo CreateModifyInfo { get;set;}
        public virtual Service Service { get; set; }

        internal protected ServiceRole()
        {

        }

        public virtual bool Equals(ServiceRole other)
        {
            if (ReferenceEquals(null, other))
            {
                return false;
            }
            if (ReferenceEquals(this, other))
            {
                return true;
            }
            return Equals(other.Service, Service);
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj))
            {
                return false;
            }
            if (ReferenceEquals(this, obj))
            {
                return true;
            }
            return Equals(obj as ServiceRole);
        }

        public override int GetHashCode()
        {
            unchecked
            {
                return  (Service != null ? Service.GetHashCode() : 0);
            }
        }

    }
}